<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员页</title>
    <script src="jq.js"></script>
    <script>
        let loginUser = null;

        function init(){
            const loginUserStr = sessionStorage.getItem("loginUser")
            //字符串转为对象
            loginUser = JSON.parse(loginUserStr);
            console.log(loginUser)
        }

        function deleteUser(){
            if(loginUser == null){
                alert("需要登录后才能进行操作")
                return;
            }
            const id = $("#id").val();
            $.post("http://localhost:8080/user/delete",{
                id:id,
                userId:loginUser.userId
            },function (res){
                if(res.code == 200){
                    alert("删除成功")
                }else{
                    alert("删除失败")
                }
            })
        }
        $(function (){
            init()
            // if(loginUser == null){
            //     location.href = "index.html"
            // }
        })
    </script>
</head>
<body>
    <a href="index.html">首页</a>
    <h1>管理员页</h1>
    <h2>只有登录后可以看</h2>
    <div>
        <input id="id" placeholder="请输入需要删除的id"/>
        <button onclick="deleteUser()">删除内容</button>
    </div>
</body>
</html>